﻿namespace Example
{
    using System;
    using Xunit;

    public sealed class LambdaFacts
    {
        public static T CallDelegate<T>(Func<T, T, T> func, T a, T b)
        {
            return func(a, b);
        }

        [Fact]
        public void assign_and_call()
        {
            Func<int, int, int> func = (a, b) => (a + b);

            const int expected = 3;
            var actual = func(1, 2);

            Assert.Equal(expected, actual);
        }

        [Fact]
        public void pass_as_parameter()
        {
            Func<int, int, int> func = (a, b) => (a + b);

            const int expected = 3;
            var actual = CallDelegate(func, 1, 2);

            Assert.Equal(expected, actual);
        }

        [Fact]
        public void with_local_variables()
        {
            Func<int> func = () =>
            {
                const int a = 1;
                const int b = 2;
                return a + b;
            };

            const int expected = 3;
            var actual = func();

            Assert.Equal(expected, actual);
        }
    }
}